﻿#region
/*******************************************************************************
** File Name:		    FoodUnitService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class FoodUnitService : IFoodUnitService
    {
		 IFoodUnit foodUnit = new FoodUnitRepository();
		 
		 #region  Auto Generation
		 

		public void UpdateByFoodUnitID (FoodUnitModel model)
		{
			EFoodUnit entity = ConvertModelToEntity(model);

            foodUnit.UpdateByFoodUnitID(entity);

		}

		public void DeleteByFoodUnitID (System.Int64 foodUnitID)
		{
		
            foodUnit.DeleteByFoodUnitID(foodUnitID);

		}
		 
        public FoodUnitModel GetByFoodUnitID (System.Int64 foodUnitID)
        {
        
			EFoodUnit entity = foodUnit.GetByFoodUnitID(foodUnitID);
			
            FoodUnitModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<FoodUnitModel> GetAll ()
		{
			IList<EFoodUnit> entity = foodUnit.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<FoodUnitModel> list = new List<FoodUnitModel>();

            foreach (var item in entity)
            {
                FoodUnitModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private FoodUnitModel ConvertEntityToModel(EFoodUnit entity)
		{
			if (entity == null)
            {
                return null;
            }
			FoodUnitModel model = new FoodUnitModel();
                        model.FoodUnitID = entity.FoodUnitID;
                        model.Name = entity.Name;
                        model.Rate = entity.Rate;
                        model.Remark = entity.Remark;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        return model;
		}
		
		private EFoodUnit ConvertModelToEntity(FoodUnitModel model)
		{
			if (model == null)
            {
                return null;
            }
			EFoodUnit entity = new EFoodUnit();
                        entity.FoodUnitID = model.FoodUnitID;
                        entity.Name = model.Name;
                        entity.Rate = model.Rate;
                        entity.Remark = model.Remark;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        return entity;
		}
		
		
		
		#endregion
    }
}